package com.phoenix.rabbitmq.controller;

import com.phoenix.rabbitmq.pojo.OrderMessage;
import com.phoenix.rabbitmq.service.producer.OrderProducerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/***
 * @Auther: 汪孟飞
 * @Description:
 * @Date: 2025-05-23 18:57
 * @Copyright:
 ***/
@RestController
@RequestMapping("/order")
public class HelloWorldController {

    @Autowired
    private OrderProducerService orderProducerService;

    @PostMapping("/create")
    public String createOrder(@RequestParam(value = "productName") String productName, @RequestParam(value = "amount") BigDecimal amount,@RequestParam(value = "quantity") Integer quantity) {
        String orderId = "ORD" + System.currentTimeMillis();
        OrderMessage orderMessage = new OrderMessage(orderId,productName,amount,quantity);

        orderProducerService.sendOrderMessage(orderMessage);
        return "订单消息发送成功，订单ID：" + orderId;
    }

    @PostMapping("/create-error")
    public String createErrorOrder() {
        String orderId = "ERR" + System.currentTimeMillis();
        OrderMessage orderMessage = new OrderMessage(orderId, "error",
                new BigDecimal("100.00"), 1);

        orderProducerService.sendOrderMessage(orderMessage);

        return "异常测试订单发送成功，订单ID：" + orderId;
    }

}
